package com.aistar.service.impl;

import com.aistar.mapper.ChoiceCollectMapper;
import com.aistar.mapper.ChoiceCommentMapper;
import com.aistar.pojo.ChoiceCollect;
import com.aistar.pojo.ChoiceComment;
import com.aistar.pojo.ChoiceCommentExample;
import com.aistar.service.ChoiceCollectService;
import com.aistar.service.ChoiceCommentService;
import com.aistar.util.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ChoiceCommentServiceImpl implements ChoiceCommentService {

    @Autowired
    private ChoiceCommentMapper choiceCommentMapper;


    @Override
    public ServerResponse add(ChoiceComment choiceComment) {
        int rows=choiceCommentMapper.insert(choiceComment);
        if(rows>0)
            return ServerResponse.addSuccess();
        return ServerResponse.addFailed();
    }

    @Override
    public ServerResponse getAll() {
        ChoiceCommentExample example=new ChoiceCommentExample();
        List<ChoiceComment> choiceCommentList= choiceCommentMapper.selectByExample(example);
        if(choiceCommentList!=null && choiceCommentList.size()>0)
            return ServerResponse.getSuccess(choiceCommentList);
        return ServerResponse.getFailed();
    }

    @Override
    public ServerResponse getById(Integer id) {
        ChoiceComment choiceComment=choiceCommentMapper.selectByPrimaryKey(id);
        if(choiceComment!=null)
            return ServerResponse.getSuccess(choiceComment);
        return ServerResponse.getFailed();
    }

    @Override
    public ServerResponse delete(Integer choiceCommentId) {
        ChoiceComment choiceComment=new ChoiceComment();
        choiceComment.setChoiceCommentId(choiceCommentId);
        choiceComment.setStatus(0);
        int rows=choiceCommentMapper.updateByPrimaryKeySelective(choiceComment);
        if(rows>0)
            return ServerResponse.deleteSuccess();
        return ServerResponse.deleteFailed();
    }


}
